package com.example.zhangxin.aaa;

import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BadgeItem;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;

public class TwoActivity extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener {

    private FrameLayout fl;
    private BottomNavigationBar btn_bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        initView();
        btn_bar.setMode(BottomNavigationBar.MODE_SHIFTING);
        btn_bar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
        BadgeItem item = new BadgeItem().setBorderWidth(4)
                .setBackgroundColor(Color.RED)
                .setText("6")
                .setHideOnSelect(true);
        btn_bar.addItem(new BottomNavigationItem(R.mipmap.ic_home_white_24dp,"书城").setActiveColorResource(R.color.orange).setBadgeItem(item))
                .addItem(new BottomNavigationItem(R.mipmap.ic_book_white_24dp,"商城").setActiveColorResource(R.color.teal))
                .addItem(new BottomNavigationItem(R.mipmap.ic_tv_white_24dp,"菜场").setActiveColorResource(R.color.blue))
                .setFirstSelectedPosition(0)
                .initialise();
        btn_bar.setTabSelectedListener(this);
    }

    private void initView() {
        fl = (FrameLayout) findViewById(R.id.fl);
        btn_bar = (BottomNavigationBar) findViewById(R.id.btn_bar);
    }

    @Override
    public void onTabSelected(int position) {
        Toast.makeText(this,position+"打开了",Toast.LENGTH_SHORT).show();
        Log.i("TAG", "onTabSelected: "+position);
    }

    @Override
    public void onTabUnselected(int position) {
        Toast.makeText(this,position+"关闭了",Toast.LENGTH_SHORT).show();
        Log.i("TAG", "onTabSelected: "+position+"关闭了");
    }

    @Override
    public void onTabReselected(int position) {
        new AsyncTask<String, Void, String>() {
            @Override
            protected String doInBackground(String... params) {
                return null;
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
            }
        }.execute("");


    }
}
